<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width=" ">
      <el-form-item label="店铺名称" prop="shopName">
        <el-input v-model="queryParams.shopName" placeholder="请输入店铺名称}" clearablew @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="店铺介绍" prop="shopIntro">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.shopIntro"-->
      <!--          placeholder="请输入店铺介绍"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="店铺评分" prop="shopRating">
        <el-input v-model="queryParams.shopRating" placeholder="请输入店铺评分" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="店铺地址" prop="shopAddress">
        <el-input v-model="queryParams.shopAddress" placeholder="请输入店铺地址" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="联系人" prop="contact">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.contact"-->
      <!--          placeholder="请输入联系人"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="联系电话" prop="contactPhone">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.contactPhone"-->
      <!--          placeholder="请输入联系电话"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="邮箱" prop="email">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.email"-->
      <!--          placeholder="请输入邮箱"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="联系地址" prop="contactAddress">
        <el-input v-model="queryParams.contactAddress" placeholder="请输入联系地址" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="删除标识" prop="isDel">
        <template slot="label">
          <span>
            删除标识
            <el-tooltip class="item" effect="dark" content="0-正常，1-停用" placement="top">
              <i class="el-icon-question"></i>
            </el-tooltip>
          </span>
        </template>
        <el-input v-model="queryParams.isDel" clearable placeholder="请输入删除标识" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="删除标识"  prop="isDel">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.isDel"-->
      <!--          placeholder="请输入删除标识（0正常，1停用）"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段1" prop="ext1">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext1"-->
      <!--          placeholder="请输入扩展字段1"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段2" prop="ext2">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext2"-->
      <!--          placeholder="请输入扩展字段2"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段3" prop="ext3">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext3"-->
      <!--          placeholder="请输入扩展字段3"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段4" prop="ext4">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext4"-->
      <!--          placeholder="请输入扩展字段4"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段5" prop="ext5">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext5"-->
      <!--          placeholder="请输入扩展字段5"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
    </el-form>

    <el-row :gutter="10" class="mb8" style="display: flex;">
      <el-col style="justify-content: left;" :span="20">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:shop:add']">新增</el-button>
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:shop:edit']">修改</el-button>
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:shop:remove']">删除</el-button>
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:shop:export']">导出</el-button>
      </el-col>
      <el-col style="justify-content: right;" class="text-right" v-show="showSearch" :span="2.5">
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :span="1.5"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="shopList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商店id" align="center" prop="shopId" />
      <el-table-column label="店铺名称" align="center" prop="shopName" />
      <!-- <el-table-column label="店铺介绍" align="center" width="150" prop="shopIntro" /> -->
      <el-table-column label="店铺评分" align="center" prop="shopRating" />
      <el-table-column label="店铺地址" align="center" width="250" prop="shopAddress" />
      <el-table-column label="联系人" align="center" prop="contact" />
      <el-table-column label="联系电话" align="center" width="120" prop="contactPhone" />
      <el-table-column label="邮箱" align="center" width="160" prop="email" />
      <!-- <el-table-column label="联系地址" align="center" width="250" prop="contactAddress" /> -->
      <!--      <el-table-column label="扩展字段1" align="center" prop="ext1" />-->
      <!--      <el-table-column label="扩展字段2" align="center" prop="ext2" />-->
      <!--      <el-table-column label="扩展字段3" align="center" prop="ext3" />-->
      <!--      <el-table-column label="扩展字段4" align="center" prop="ext4" />-->
      <!--      <el-table-column label="扩展字段5" align="center" prop="ext5" />-->
      <el-table-column label="创建时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="删除标识" align="center" prop="isDel" />
      <!-- <el-table-column label="更新时间" align="center" prop="updateTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['monitor:job:query']"
          >详细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改商店信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="openEdit" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="店铺id" prop="shoId">
          <el-input v-model="form.shopId" placeholder="店铺id自动生成，不必填写" readonly/>
        </el-form-item>
        <el-form-item label="店铺名称" prop="shopName">
          <el-input v-model="form.shopName" placeholder="请输入店铺名称" />
        </el-form-item>
        <el-form-item label="店铺介绍" prop="shopIntro">
          <editor v-model="form.shopIntro" :min-height="192" />
        </el-form-item>
        <el-form-item label="店铺评分" prop="shopRating">
          <el-input v-model="form.shopRating" placeholder="请输入店铺评分" />
        </el-form-item>
        <el-form-item label="店铺地址" prop="shopAddress">
          <el-input v-model="form.shopAddress" placeholder="请输入店铺地址" />
        </el-form-item>
        <el-form-item label="联系人" prop="contact">
          <el-input v-model="form.contact" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="contactPhone">
          <el-input v-model="form.contactPhone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="联系地址" prop="contactAddress">
          <el-input v-model="form.contactAddress" placeholder="请输入联系地址" />
        </el-form-item>
        <el-form-item label="删除标识" prop="isDel">
          <template slot="label">
            <span>
              删除标识
              <el-tooltip class="item" effect="dark" content="0-正常，1-停用" placement="top">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </span>
          </template>
          <el-input v-model="form.isDel" placeholder="请输入删除标识（0-正常，1-停用）" />
        </el-form-item>
        <!--        <el-form-item label="扩展字段1" prop="ext1">-->
        <!--          <el-input v-model="form.ext1" placeholder="请输入扩展字段1" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段2" prop="ext2">-->
        <!--          <el-input v-model="form.ext2" placeholder="请输入扩展字段2" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段3" prop="ext3">-->
        <!--          <el-input v-model="form.ext3" placeholder="请输入扩展字段3" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段4" prop="ext4">-->
        <!--          <el-input v-model="form.ext4" placeholder="请输入扩展字段4" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段5" prop="ext5">-->
        <!--          <el-input v-model="form.ext5" placeholder="请输入扩展字段5" />-->
        <!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="openView" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="店铺id" prop="shoId">
          <el-input v-model="form.shopId" placeholder="店铺id自动生成，不必填写" readonly/>
        </el-form-item>
        <el-form-item label="店铺名称" prop="shopName">
          <el-input v-model="form.shopName" placeholder="未填入店铺名称" readonly/>
        </el-form-item>
        <el-form-item label="店铺介绍" prop="shopIntro">
          <editor v-model="form.shopIntro" :min-height="192" placeholder="未填入店铺介绍" readonly />
        </el-form-item>
        <el-form-item label="店铺评分" prop="shopRating">
          <el-input v-model="form.shopRating" placeholder="未填入店铺评分" readonly/>
        </el-form-item>
        <el-form-item label="店铺地址" prop="shopAddress">
          <el-input v-model="form.shopAddress" placeholder="未填入店铺地址" readonly/>
        </el-form-item>
        <el-form-item label="联系人" prop="contact">
          <el-input v-model="form.contact" placeholder="未填入联系人" readonly/>
        </el-form-item>
        <el-form-item label="联系电话" prop="contactPhone">
          <el-input v-model="form.contactPhone" placeholder="未填入联系电话" readonly/>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="未填入邮箱" readonly/>
        </el-form-item>
        <el-form-item label="联系地址" prop="contactAddress">
          <el-input v-model="form.contactAddress" placeholder="未填入联系地址" readonly/>
        </el-form-item>
        <el-form-item label="删除标识" prop="isDel">
          <template slot="label">
            <span>
              删除标识
              <el-tooltip class="item" effect="dark" content="0-正常，1-停用" placement="top">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </span>
          </template>
          <el-input v-model="form.isDel" placeholder="未填入删除标识（0-正常，1-停用）" readonly/>
        </el-form-item>
        <!--        <el-form-item label="扩展字段1" prop="ext1">-->
        <!--          <el-input v-model="form.ext1" placeholder="请输入扩展字段1" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段2" prop="ext2">-->
        <!--          <el-input v-model="form.ext2" placeholder="请输入扩展字段2" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段3" prop="ext3">-->
        <!--          <el-input v-model="form.ext3" placeholder="请输入扩展字段3" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段4" prop="ext4">-->
        <!--          <el-input v-model="form.ext4" placeholder="请输入扩展字段4" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段5" prop="ext5">-->
        <!--          <el-input v-model="form.ext5" placeholder="请输入扩展字段5" />-->
        <!--        </el-form-item>-->
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listShop, getShop, delShop, addShop, updateShop } from "@/api/system/shop";

export default {
  name: "Shop",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商店信息管理表格数据
      shopList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      openEdit: false,
      openView: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        shopName: null,
        shopIntro: null,
        shopRating: null,
        shopAddress: null,
        contact: null,
        contactPhone: null,
        email: null,
        contactAddress: null,
        isDel: null,
        ext1: null,
        ext2: null,
        ext3: null,
        ext4: null,
        ext5: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商店信息管理列表 */
    getList() {
      this.loading = true;
      listShop(this.queryParams).then(response => {
        this.shopList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.openEdit = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        shopId: null,
        shopName: null,
        shopIntro: null,
        shopRating: null,
        shopAddress: null,
        contact: null,
        contactPhone: null,
        email: null,
        contactAddress: null,
        isDel: null,
        createTime: null,
        updateTime: null,
        ext1: null,
        ext2: null,
        ext3: null,
        ext4: null,
        ext5: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.shopId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openEdit = true;
      this.title = "添加商店信息管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const shopId = row.shopId || this.ids
      getShop(shopId).then(response => {
        this.form = response.data;
        this.openEdit = true;
        this.title = "修改商店信息管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.shopId != null) {
            updateShop(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openEdit = false;
              this.getList();
            });
          } else {
            addShop(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openEdit = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const shopIds = row.shopId || this.ids;
      this.$modal.confirm('是否确认删除商店信息管理Id为"' + shopIds + '"的数据项？').then(function () {
        return delShop(shopIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 详细按钮操作 */
    handleView(row) {
      this.openView = true;
      this.form = row;
      this.title = "商店信息管理详细（如需修改，请通过修改按钮进行修改";
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/shop/export', {
        ...this.queryParams
      }, `shop_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
